主题
设置窗口客户区偏移 - SetClientLocation
函数简介
设置绑定窗口客户区左上角在截图/远程帧坐标系中的偏移量 (x, y)。
适用于 VNC 全屏截图 等场景:远程画面是整个 framebuffer,插件无法像本地前台那样通过窗口句柄自动得到客户区在屏幕上的位置。调用本接口后,可在不修改任何截图参数的前提下,让脚本仍按窗口相对坐标编写逻辑。
坐标转换规则
| 方向 | 规则 |
|---|---|
| 截图 | Capture、CaptureMat(0,0,0,0) 等不做任何修改,始终按帧/全屏原样截取。 |
| 找图/找色返回坐标 | 内部在返回前 减去 (x, y),得到窗口相对坐标。 |
| 鼠标移动/点击 | 传入窗口相对坐标时,内部 加上 (x, y) 再发送到远程/屏幕。 |
| GetCursorPos | 返回窗口相对坐标,内部 减去 (x, y)。 |
传 (0, 0) 可清除偏移,恢复默认行为。
典型使用场景
- 使用 BindWindowEx 绑定,
display为vnc,mouse为vnc(或前台键鼠 + VNC 截图)。 - SetConfig 中配置 VNC 地址与端口。
- 人工确认目标窗口客户区在 VNC 画面中的左上角位置,调用
SetClientLocation。 - 脚本中区域参数、鼠标坐标均按窗口相对坐标书写;找图结果自动转为窗口坐标。
接口名称
SetClientLocationDLL调用
int SetClientLocation(long ola, int x, int y);参数说明
| 参数名 | 类型 | 说明 |
|---|---|---|
| ola | 长整数型 | OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。 |
| x | 整数型 | 客户区左上角在截图/远程帧中的 X 偏移。 |
| y | 整数型 | 客户区左上角在截图/远程帧中的 Y 偏移。 |
示例
SDK 调用
cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
// 操作成功
}csharp
using OLAPlug;
var ola = new OLAPlugServer();
int ret = ola.SetClientLocation(100, 200);
if (ret == 1)
{
// 操作成功
}python
from OLAPlugServer import OLAPlugServer
ola = OLAPlugServer()
ret = ola.SetClientLocation(100, 200)
if ret == 1:
pass # 操作成功java
import com.olaplug.OLAPlugServer;
OLAPlugServer ola = new OLAPlugServer();
int ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
// 操作成功
}cpp
var ola = com("OlaPlug.OlaSoft")
var ret = ola.SetClientLocation(100, 200)
if(ret == 1) {
// 操作成功
}vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ret = ola.SetClientLocation(100, 200)
If ret = 1 Then
' 操作成功
End Iftext
.局部变量 ola, OLAPlug
ola.创建 ()
ret = ola.SetClientLocation(100, 200)
.如果真 (ret = 1)
' 操作成功
.如果真结束aardio
import OLAPlugServer;
var ola = OLAPlugServer();
var ret = ola.SetClientLocation(100, 200);
if(ret == 1){
// 操作成功
}text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
整数 ret = ola.SetClientLocation(100, 200)
如果真 (ret = 1)
{
// 操作成功
}cpp
#include "OLAPlugServer.h"
OLAPlugServer ola;
int32_t ret = ola.SetClientLocation(100, 200);
if (ret == 1) {
// 操作成功
}原生 DLL 调用
cpp
long instance = CreateCOLAPlugInterFace();
SetClientLocation(instance, 100, 200);csharp
using System.Runtime.InteropServices;
using System.Text;
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int SetClientLocation(long ola, int x, int y);
long instance = CreateCOLAPlugInterFace();
SetClientLocation(instance, 100, 200);python
from ctypes import CDLL, c_int, c_int64, create_string_buffer
ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ola.SetClientLocation(instance, 100, 200)返回值
| 值 | 说明 |
|---|---|
| 1 | 成功 |
| 0 | 失败(如 OLA 对象无效) |
受影响的接口
返回坐标会减去偏移(帧坐标 → 窗口相对坐标)
找图 / 匹配
MatchWindowsFromPtr/MatchWindowsFromPtrAllMatchWindowsFromPath/MatchWindowsFromPathAllMatchWindowsThresholdFromPtr/MatchWindowsThresholdFromPtrAllMatchWindowsThresholdFromPath/MatchWindowsThresholdFromPathAllFindWindowsFromPtr/FindWindowsFromPtrAllFindWindowsFromPath/FindWindowsFromPathAll
找色 / 色块
FindColor/FindColorList/FindColorEx/FindColorListExFindMultiColor/FindMultiColorListFindColorBlock/FindColorBlockList/FindColorBlockEx/FindColorBlockListEx
以上均为基于窗口截图(
CaptureMat)且返回坐标的接口。*Ptr、内存图类接口(如MatchImageFromPtr)不受影响。
输入坐标会加上偏移(窗口相对坐标 → 帧坐标)
鼠标移动
鼠标位置读取(返回值减偏移)
GetCursorPos
间接受影响(使用当前光标位置,需先 MoveTo 到正确窗口坐标)
LeftClick/LeftDoubleClick/LeftDown/LeftUpRightClick/RightDoubleClick/RightDown/RightUpMiddleClick/MiddleDoubleClick/MiddleDown/MiddleUpWheelUp/WheelDown
相对移动
- MoveR 本身不传绝对坐标;效果依赖移动前的光标位置。
不受影响的接口
| 类别 | 说明 |
|---|---|
| 截图 | Capture、CaptureGif、GetScreenData*、LockDisplay 等;含 (0,0,0,0) 全屏。 |
| 取色/比色 | GetColor、CmpColor*、GetColorNum 等;坐标按帧坐标使用,若要用窗口相对坐标需自行 x+offsetX, y+offsetY。 |
| 内存图 | MatchImageFromPtr、FindImageFromPtr 等 *Ptr / 非绑定窗口源图接口。 |
| 坐标转换 | ClientToScreen、ScreenToClient。 |
| OCR | Ocr、OcrEx、OcrDetails 等(当前版本未接入偏移转换)。 |
| 动画匹配 | MatchAnimationFromPtr、MatchAnimationFromPath(当前版本未接入偏移转换)。 |
注意事项
- 先绑定再设置:建议在 BindWindow / BindWindowEx 成功后调用;偏移按 OLA 实例 保存,与绑定窗口配合使用。
- 偏移需人工标定:VNC 画面里用外部工具量出客户区左上角像素位置,再填入
x, y。 - 截图区域参数不变:
MatchWindows*(x1,y1,x2,y2)等区域仍按帧/全屏坐标系传入(全屏常用0,0,0,0);仅返回值转为窗口坐标。 - 取色坐标:
GetColor(x, y)的x, y为帧坐标;窗口相对取色请使用GetColor(x+offsetX, y+offsetY)。 - 解绑不清除:调用 UnBindWindow 不会自动清零偏移,需要时请
SetClientLocation(0, 0)。
与其它模块的关系
| 模块 | 关系 |
|---|---|
| 窗口 | VNC 绑定后配合本接口实现「全屏帧 + 窗口逻辑坐标」。 |
| 图像识别 | MatchWindows*、FindWindows* 返回坐标自动转换。 |
| 鼠标 | MoveTo 系列与点击类接口自动转换。 |
| 设置 | VNC 端口等仍通过 SetConfig 配置。 |
